package com.bosssoft.ecds.controller;

/**
 * @author 张东海
 * @date 2020/8/10
 * @description 票据申领具体信息Controller，提供了基本的增删改查
 *               票据申领具体信息指：单位向财政发起某次票据申领请求时，所附带的
 *               若干项、单位端所需的票据的具体信息。包括票据八位编码，以及所需
 *               数量等。
 */

import cn.hutool.core.bean.BeanUtil;
import com.bosssoft.ecds.common.response.CommonCode;
import com.bosssoft.ecds.common.response.QueryResponseResult;
import com.bosssoft.ecds.common.response.ResponseResult;
import com.bosssoft.ecds.entity.po.UbeStockFinanceapplyItemPO;
import com.bosssoft.ecds.entity.vo.UbeStockFinanceapplyItemVO;
import com.bosssoft.ecds.service.impl.UbeStockFinanceapplyItemServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class UbeStockFinanceapplyItemController {

    @Resource
    UbeStockFinanceapplyItemServiceImpl ubeStockFinanceapplyItemService;

    @GetMapping("ubeStockFinanceapplyItem")
    public QueryResponseResult getById(BigInteger id){
        UbeStockFinanceapplyItemPO financeapplyItemPO = ubeStockFinanceapplyItemService.getByPrimaryKey(id);
        return new QueryResponseResult(CommonCode.SUCCESS,financeapplyItemPO);
    }

    @GetMapping("ubeStockFinanceapplyItem/getAll")
    public QueryResponseResult getAll(){
        List<UbeStockFinanceapplyItemPO> pos = ubeStockFinanceapplyItemService.getAll();
        List<UbeStockFinanceapplyItemVO> itemVOList = pos.stream()
                .map(po -> {
                    UbeStockFinanceapplyItemVO vo = new UbeStockFinanceapplyItemVO();
                    BeanUtil.copyProperties(po, vo);
                    return vo;
                })
                .collect(Collectors.toList());
        return new QueryResponseResult(CommonCode.SUCCESS,itemVOList);
    }

    @PostMapping("ubeStockFinanceapplyItem")
    public ResponseResult create(UbeStockFinanceapplyItemPO ubeStockFinanceapplyItem){
        int insert = ubeStockFinanceapplyItemService.insert(ubeStockFinanceapplyItem);
        if(insert > 0){
            return ResponseResult.SUCCESS();
        }else {
            return ResponseResult.FAIL();
        }

    }

    @PutMapping("ubeStockFinanceapplyItem")
    public ResponseResult update(UbeStockFinanceapplyItemPO ubeStockFinanceapplyItem){
        ubeStockFinanceapplyItemService.update(ubeStockFinanceapplyItem);
        return ResponseResult.SUCCESS();
    }

    @DeleteMapping("ubeStockFinanceapplyItem")
    public ResponseResult delete(BigInteger id){
        ubeStockFinanceapplyItemService.delete(id);
        return ResponseResult.SUCCESS();
    }

}
